<!DOCTYPE html>
<script src=../resources/testharness.js></script>
<script src=../resources/testharnessreport.js></script>
<script>

// Checks navigator.mediaCapabilities.encodingInfo() with some MIME types that
// should be recordable and a few that shouldn't.
// A list of test cases. Each test case consists of [MIME type, is supported].
const recordTypeTestCases = [
  [ 'video/webm', true ],
  [ 'video/webm;codecs=vp8', true ],
  [ 'video/webm;codecs=vp9', true ],
  [ 'video/webm;codecs=vp8.0', true ],
  [ 'video/webm;codecs=vp9.0', true ],
  // 'video/webm' supports audio codec specification, see
  // http://www.webmproject.org/docs/container/
  [ 'video/webm;codecs="vp8,opus"', true ],
  [ 'video/WEBM;codecs="VP8,OPUS"', true ],
  [ 'video/webm;codecs="vp9,opus"', true ],
  [ 'video/webm;codecs="vp8,vp9,opus"', true ],
  [ 'audio/webm', true ],
  [ 'audio/webm;codecs=opus', true ],
  // Rejected MIME types
  [ 'video/invalid', false],
  [ 'video/mpeg4', false],
  [ 'video/webm;codecs=daala', false],
  [ 'audio/invalid', false],
  [ 'audio/ogg', false],
  [ 'audio/webm;codecs=vorbis', false]];

function composeQuery(mimeType, queryType) {
  const media = mimeType.split('/')[0];
  assert_true(media == 'video' || media == 'audio', 'Unsupported media type');
  if (media == 'video') {
    return {
      type : queryType,
      video : {
        contentType : mimeType,
        width : 640,
        height : 480,
        bitrate : 10000,
        framerate : 30}};
  }
  return {type : queryType, audio : {contentType : mimeType}};
}

// Tests encodingInfo()'s response for "record" type request.
recordTypeTestCases.forEach((testCase) => {
  const queryType = 'record'
  const mimeType = testCase[0];
  const isSupported = testCase[1];
  const testName = 'MediaEncodingConfiguration {type:' + queryType + ' video:{contentType:' + mimeType + '}}';
  promise_test(() => navigator.mediaCapabilities.encodingInfo(
    composeQuery(mimeType, queryType)).then(
      (result) => {
        assert_equals(result.supported, isSupported, mimeType + ' supported?');
      }),
               testName);
});

</script>
